/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.awt.Point;
import model.Bishop;
import model.King;
import model.Knight;
import model.Pawn;
import model.Player;
import model.Queen;
import model.Rook;
import view.FieldofJustice;

/**
 *
 * @author Jonas
 */
public class Game {

    public static final FieldofJustice[][] FIELDLIST = new FieldofJustice[8][8];
    private Player player1;
    private Player player2;
    private Player activePlayer;

    public Game(String spiller1Navn, String spiller2Navn) {
        player1 = new Player(spiller1Navn);
        player2 = new Player(spiller2Navn);
        makePieces(true);
        makePieces(false);
        activePlayer = player1;
    }

    private void makePieces(boolean color) {
        int brik = 1;
        while (brik <= 6) {
            switch (brik) {
                case 1:                                                         // tårn
                    if (color) {
                        player1.getChessPieceList().add(new Rook("Tårn", color, new Point(1, 8)));
                        player1.getChessPieceList().add(new Rook("Tårn", color, new Point(8, 8)));
                    } else {
                        player2.getChessPieceList().add(new Rook("Tårn", color, new Point(1, 1)));
                        player2.getChessPieceList().add(new Rook("Tårn", color, new Point(8, 1)));
                    }
                    break;
                case 2:
                    if (color) {
                        player1.getChessPieceList().add(new Knight("Springer", color, new Point(2, 8)));
                        player1.getChessPieceList().add(new Knight("Springer", color, new Point(7, 8)));
                    } else {
                        player2.getChessPieceList().add(new Knight("Springer", color, new Point(2, 1)));
                        player2.getChessPieceList().add(new Knight("Springer", color, new Point(7, 1)));
                    }
                    break;
                case 3:
                    if (color) {
                        player1.getChessPieceList().add(new Bishop("Løber", color, new Point(3, 8)));
                        player1.getChessPieceList().add(new Bishop("Løber", color, new Point(6, 8)));
                    } else {
                        player2.getChessPieceList().add(new Bishop("Løber", color, new Point(3, 1)));
                        player2.getChessPieceList().add(new Bishop("Løber", color, new Point(6, 1)));
                    }
                    break;
                case 4:
                    if (color) {
                        player1.getChessPieceList().add(new King("Konge", color, new Point(5, 8)));
                    } else {
                        player2.getChessPieceList().add(new King("Konge", color, new Point(5, 1)));
                    }
                    break;
                case 5:
                    if (color) {
                        player1.getChessPieceList().add(new Queen("Dronning", color, new Point(4, 8)));
                    } else {
                        player2.getChessPieceList().add(new Queen("Dronning", color, new Point(4, 1)));
                    }
                    break;
                case 6:
                    if (color) {                        
                        for (int i = 1; i < 9; i++) {
                            player1.getChessPieceList().add(new Pawn("Bonde", color, new Point(i, 7)));
                        }
                    } else {
                       for (int i = 1; i < 9; i++) {
                            player2.getChessPieceList().add(new Pawn("Bonde", color, new Point(i, 2)));
                        }
                    }
                    break;
            }
            brik++;
        }

    }

    public boolean move(Point piecePosition, Point dest) {
        for (int i = 0; i < activePlayer.getChessPieceList().size(); i++) {
            if(activePlayer.getChessPieceList().get(i).getPosition().distance(piecePosition.x, piecePosition.y)==0){
                if(activePlayer.getChessPieceList().get(i).canMoveTo(dest.x, dest.y)){
                    
                }
            }
        }
        
        return true;
    }

    
    
    public Player getPlayer1() {
        return player1;
    }

    public Player getPlayer2() {
        return player2;
    }
    
    

}
